package 字符串;

/**
 * @Author Weton Li
 * @Date 2021/8/29 14:16
 */
public class IP地址无效化 {
    public static void main(String[] args) {
        String address = "255.100.50.0";
        System.out.println(defangIPaddr1(address));
        System.out.println(defangIPaddr2(address));

        String s1 = "he";
        String s2 = s1 + "llo";
        System.out.println(s1==s2);
        int i =0,s=0;
        do{
            if (i % 2 == 0) {
                i++;
                continue;
            }
            i++;s+=i;
        }while (i<7);
        System.out.println(s);
        System.out.println(10%2*3);
    }

    public static String defangIPaddr1(String address) {
        return address.replace(".", "[.]");
    }

    public static String defangIPaddr2(String address) {
        char[] chars = address.toCharArray();
        StringBuffer sb = new StringBuffer();
        for (char c : chars) {
            if (c == '.') { // 如果当前字符是“点”，则向sb中追加[.]后立刻执行下一轮循环，不用再追加当前c(.)
                sb.append("[.]");
                continue;
            }
            sb.append(c);
        }
        return sb.toString();
    }
}
